package xcmg.device.web.ratingManager;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import xcmg.device.infra.BasicController;
import xcmg.device.infra.ErrorCode;
import xcmg.device.service.ratingManager.RatingConfigTimeService;
import xcmg.device.service.vo.ratingManager.RatingConfigTimeVO;
import yb.ecp.fast.infra.annotation.FastMappingInfo;
import yb.ecp.fast.infra.infra.ActionResult;

/**
 * Created by wrg on 2019/7/10.
 */
@RestController
@RequestMapping("/ratingConfigTime")
@Api("评级管理时间配置入口")
public class RatingConfigTimeController extends BasicController{
    @Autowired
    private RatingConfigTimeService ratingConfigTimeService;

    @PostMapping(value = "/add")
    @ApiOperation(value = "新增时间配置")
    @FastMappingInfo(needLogin = true)
    public ActionResult add(@RequestBody RatingConfigTimeVO ratingConfigTimeVO) throws Exception {
        if (null == ratingConfigTimeVO){
            return actionResult(ErrorCode.IllegalArument);
        }

        return actionResult(ratingConfigTimeService.add(ratingConfigTimeVO));
    }

    @PostMapping(value = "/update")
    @ApiOperation(value = "修改时间配置")
    @FastMappingInfo(needLogin = true)
    public ActionResult update(@RequestBody RatingConfigTimeVO ratingConfigTimeVO) throws Exception {
        if (null == ratingConfigTimeVO){
            return actionResult(ErrorCode.IllegalArument);
        }

        return actionResult(ratingConfigTimeService.update(ratingConfigTimeVO));
    }

    @GetMapping(value = "/item")
    @ApiOperation(value = "获取时间配置")
    @FastMappingInfo(needLogin = true)
    public ActionResult item(@RequestParam("ratingId") String ratingId,@RequestParam("type") Integer type) throws Exception {
        if (StringUtils.isBlank(ratingId) || null == type) {
            return actionResult(ErrorCode.IllegalArument);
        }
        return actionValueResult(ratingConfigTimeService.item(ratingId,type));
    }
}
